import { EndpointParams } from "@aws-sdk/util-endpoints"

export interface TestCase{
  documentation:string,
  params:EndpointParams,
  expect:Record<string,Object>,
}
export interface TestCases {
  testCases:TestCase[]
  version?:string
}
export const testCases:TestCases[] = [
  {
    "testCases": [
      {
        "documentation": "simple region endpoint",
        "params": {
          "region": "us-east-1"
        },
        "expect": {
          "endpoint": {
            "url": "https://events.us-east-1.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "basic case of endpointId",
        "params": {
          "region": "us-east-1",
          "endpointId": "myendpoint"
        },
        "expect": {
          "endpoint": {
            "properties": {
              "authSchemes": [
                {
                  "name": "sigv4a",
                  "signingName": "events",
                  "signingRegionSet": ["*"]
                }
              ]
            },
            "url": "https://myendpoint.endpoint.events.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "endpointId & FIPS",
        "params": {
          "region": "us-east-1",
          "endpointId": "myendpoint",
          "useFIPSEndpoint": true
        },
        "expect": {
          "error": "FIPS endpoints not supported with multi-region endpoints"
        }
      }
    ],
    "version": "1.4"
  },
  {
    "testCases": [
      {
        "documentation": "test where URI is set and flows to URI and header",
        "params": {
          "Uri": "https://www.example.com",
          "Arn": "arn:aws:s3:us-east-2:012345678:outpost:op-1234"
        },
        "expect": {
          "endpoint": {
            "headers": {
              "x-uri": ["https://www.example.com"],
              "x-arn-region": ["us-east-2"]
            },
            "url": "https://www.example.com/"
          }
        }
      },
      {
        "documentation": "test where explicit error is set",
        "params": {
          "CustomError": "This is an error!"
        },
        "expect": {
          "error": "This is an error!"
        }
      },
      {
        "documentation": "test where an ARN field is used in the error directly",
        "params": {
          "Arn": "arn:This is an error!:s3:us-east-2:012345678:outpost:op-1234"
        },
        "expect": {
          "error": "This is an error!"
        }
      },
      {
        "documentation": "test case where no fields are set",
        "params": {},
        "expect": {
          "error": "No fields were set"
        }
      }
    ],
    "version": "1.4"
  },
  {
    "version": "1.0",
    "testCases": [
      {
        "documentation": "bucket-name:  isVirtualHostable",
        "params": {
          "BucketName": "bucket-name"
        },
        "expect": {
          "endpoint": {
            "url": "https://bucket-name.s3.amazonaws.com/"
          }
        }
      },
      {
        "documentation": "bucket-with-number-1: isVirtualHostable",
        "params": {
          "BucketName": "bucket-with-number-1"
        },
        "expect": {
          "endpoint": {
            "url": "https://bucket-with-number-1.s3.amazonaws.com/"
          }
        }
      },
      {
        "documentation": "BucketName: not isVirtualHostable (uppercase characters)",
        "params": {
          "BucketName": "BucketName"
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      },
      {
        "documentation": "bucket_name: not isVirtualHostable (underscore)",
        "params": {
          "BucketName": "bucket_name"
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      },
      {
        "documentation": "bucket.name: isVirtualHostable (http only)",
        "params": {
          "BucketName": "bucket.name"
        },
        "expect": {
          "endpoint": {
            "url": "http://bucket.name.s3.amazonaws.com/"
          }
        }
      },
      {
        "documentation": "bucket.name.multiple.dots1: isVirtualHostable (http only)",
        "params": {
          "BucketName": "bucket.name.multiple.dots1"
        },
        "expect": {
          "endpoint": {
            "url": "http://bucket.name.multiple.dots1.s3.amazonaws.com/"
          }
        }
      },
      {
        "documentation": "-bucket-name: not isVirtualHostable (leading dash)",
        "params": {
          "BucketName": "-bucket-name"
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      },
      {
        "documentation": "bucket-name-: not isVirtualHostable (trailing dash)",
        "params": {
          "BucketName": "bucket-name-"
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      },
      {
        "documentation": "aa: not isVirtualHostable (< 3 characters)",
        "params": {
          "BucketName": "aa"
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      },
      {
        "documentation": "'a'*64: not isVirtualHostable (> 63 characters)",
        "params": {
          "BucketName": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      },
      {
        "documentation": ".bucket-name: not isVirtualHostable (leading dot)",
        "params": {
          "BucketName": ".bucket-name"
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      },
      {
        "documentation": "bucket-name.: not isVirtualHostable (trailing dot)",
        "params": {
          "BucketName": "bucket-name."
        },
        "expect": {
          "error": "not isVirtualHostableS3Bucket"
        }
      }
    ]
  },
  {
    "testCases": [
      {
        "documentation": "arn + region resolution",
        "params": {
          "Bucket": "arn:aws:s3:us-east-2:012345678:outpost:op-1234",
          "Region": "us-east-2"
        },
        "expect": {
          "endpoint": {
            "url": "https://op-1234-012345678.us-east-2.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "arn, unset outpost id",
        "params": {
          "Bucket": "arn:aws:s3:us-east-2:012345678:outpost",
          "Region": "us-east-2"
        },
        "expect": {
          "error": "Invalid ARN: outpostId was not set"
        }
      },
      {
        "documentation": "arn, empty outpost id (tests that empty strings are handled properly during matching)",
        "params": {
          "Bucket": "arn:aws:s3:us-east-2:012345678:outpost::",
          "Region": "us-east-2"
        },
        "expect": {
          "error": "OutpostId was empty"
        }
      },
      {
        "documentation": "arn, empty outpost id (tests that ARN parsing considers a trailing colon)",
        "params": {
          "Bucket": "arn:aws:s3:us-east-2:012345678:outpost:",
          "Region": "us-east-2"
        },
        "expect": {
          "error": "OutpostId was empty"
        }
      },
      {
        "documentation": "valid hostlabel + region resolution",
        "params": {
          "Bucket": "mybucket",
          "Region": "us-east-2"
        },
        "expect": {
          "endpoint": {
            "url": "https://mybucket.us-east-2.amazonaws.com/"
          }
        }
      },
      {
        "documentation": "not a valid hostlabel + region resolution",
        "params": {
          "Bucket": "99_a",
          "Region": "us-east-2"
        },
        "expect": {
          "endpoint": {
            "url": "https://us-east-2.amazonaws.com/99_a"
          }
        }
      },
      {
        "documentation": "no bucket",
        "params": {
          "Region": "us-east-2"
        },
        "expect": {
          "endpoint": {
            "url": "https://us-east-2.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "a string that is not a 6-part ARN",
        "params": {
          "TestCaseId": "invalid-arn",
          "Bucket": "asdf"
        },
        "expect": {
          "error": "Test case passed: `asdf` is not a valid ARN."
        }
      },
      {
        "documentation": "resource id MUST not be null",
        "params": {
          "TestCaseId": "invalid-arn",
          "Bucket": "arn:aws:s3:us-west-2:123456789012:"
        },
        "expect": {
          "error": "Test case passed: `arn:aws:s3:us-west-2:123456789012:` is not a valid ARN."
        }
      },
      {
        "documentation": "service MUST not be null",
        "params": {
          "TestCaseId": "invalid-arn",
          "Bucket": "arn:aws::us-west-2:123456789012:resource-id"
        },
        "expect": {
          "error": "Test case passed: `arn:aws::us-west-2:123456789012:resource-id` is not a valid ARN."
        }
      },
      {
        "documentation": "partition MUST not be null",
        "params": {
          "TestCaseId": "invalid-arn",
          "Bucket": "arn::s3:us-west-2:123456789012:resource-id"
        },
        "expect": {
          "error": "Test case passed: `arn::s3:us-west-2:123456789012:resource-id` is not a valid ARN."
        }
      },
      {
        "documentation": "region MAY be null",
        "params": {
          "TestCaseId": "valid-arn",
          "Bucket": "arn:aws:s3::123456789012:resource-id"
        },
        "expect": {
          "error": "Test case passed: A valid ARN was parsed: service: `s3`, partition: `aws, region: ``, accountId: `123456789012`, resource: `resource-id`"
        }
      },
      {
        "documentation": "accountId MAY be null",
        "params": {
          "TestCaseId": "valid-arn",
          "Bucket": "arn:aws:s3:us-east-1::resource-id"
        },
        "expect": {
          "error": "Test case passed: A valid ARN was parsed: service: `s3`, partition: `aws, region: `us-east-1`, accountId: ``, resource: `resource-id`"
        }
      },
      {
        "documentation": "accountId MAY be non-numeric",
        "params": {
          "TestCaseId": "valid-arn",
          "Bucket": "arn:aws:s3:us-east-1:abcd:resource-id"
        },
        "expect": {
          "error": "Test case passed: A valid ARN was parsed: service: `s3`, partition: `aws, region: `us-east-1`, accountId: `abcd`, resource: `resource-id`"
        }
      }
    ],
    "version": "1.4"
  },
  {
    "testCases": [
      {
        "documentation": "standard AWS region",
        "params": {
          "Region": "us-east-2"
        },
        "expect": {
          "endpoint": {
            "properties": {
              "authSchemes": [
                {
                  "name": "sigv4",
                  "signingName": "serviceName",
                  "signingRegion": "us-east-2"
                }
              ],
              "meta": {
                "baseSuffix": "mockDefaultDnsSuffix",
                "dualStackSuffix": "mockDefaultDualStackDnsSuffix"
              }
            },
            "url": "https://aws-partition.us-east-2.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "AWS region that doesn't match any regexes",
        "params": {
          "Region": "mars-global"
        },
        "expect": {
          "endpoint": {
            "properties": {
              "authSchemes": [
                {
                  "name": "sigv4",
                  "signingName": "serviceName",
                  "signingRegion": "mars-global"
                }
              ],
              "meta": {
                "baseSuffix": "mockDefaultDnsSuffix",
                "dualStackSuffix": "mockDefaultDualStackDnsSuffix"
              }
            },
            "url": "https://aws-partition.mars-global.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "AWS region that matches the AWS regex",
        "params": {
          "Region": "us-east-10"
        },
        "expect": {
          "endpoint": {
            "properties": {
              "authSchemes": [
                {
                  "name": "sigv4",
                  "signingName": "serviceName",
                  "signingRegion": "us-east-10"
                }
              ],
              "meta": {
                "baseSuffix": "mockDefaultDnsSuffix",
                "dualStackSuffix": "mockDefaultDualStackDnsSuffix"
              }
            },
            "url": "https://aws-partition.us-east-10.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "CN region that matches the AWS regex",
        "params": {
          "Region": "cn-north-5"
        },
        "expect": {
          "endpoint": {
            "properties": {
              "authSchemes": [
                {
                  "name": "sigv4",
                  "signingName": "serviceName",
                  "signingRegion": "cn-north-5"
                }
              ],
              "meta": {
                "baseSuffix": "mockDefaultDnsSuffix",
                "dualStackSuffix": "mockDefaultDualStackDnsSuffix"
              }
            },
            "url": "https://aws-partition.cn-north-5.mockdefaultdnssuffix/"
          }
        }
      },
      {
        "documentation": "CN region that is in the explicit list",
        "params": {
          "Region": "aws-cn-global"
        },
        "expect": {
          "endpoint": {
            "properties": {
              "authSchemes": [
                {
                  "name": "sigv4",
                  "signingName": "serviceName",
                  "signingRegion": "aws-cn-global"
                }
              ],
              "meta": {
                "baseSuffix": "mockDefaultDnsSuffix",
                "dualStackSuffix": "mockDefaultDualStackDnsSuffix"
              }
            },
            "url": "https://aws-partition.aws-cn-global.mockdefaultdnssuffix/"
          }
        }
      }
    ]
  }
]